const TeachMaterial = require('../modules/teachmaterial');
const LearnContent = require('../modules/learningcontent');

class TeachMaterialController{

    static async index(ctx) {
        try {
            const data = {}
            let tm = await new TeachMaterial()
            data.teachMaterialList = await tm.listALl()
            await ctx.render('teachmaterial/index', data)
        } catch(err) {
            await ctx.render('error', {message: err.message})
        }
    }

    static async detail(ctx) {
        try {
            const id = ctx.params.id
            let data = {}
            let tm = await new TeachMaterial()
            let res = await tm.getOne(id);
            let lc = await new LearnContent()
            let learnContents = await lc.listByTeachMaterial(id);
            data.teachMaterial = res;
            data.learnContents = learnContents;
            await ctx.render('teachmaterial/detail', data)
        } catch(err) {
            await ctx.render('error', {message: err.message})
        }
    }

    // static async add(ctx) {
    //     try {
    //         const id = ctx.params.id
    //         const data = {}
    //         data.teachMaterial = await new TeachMaterial().getOne(id)
    //         await ctx.render('teachmaterial/detail', data)
    //     } catch(err) {
    //         await ctx.render('error', {message: err.message})
    //     }
    // }
    
}

exports = module.exports = TeachMaterialController;